/**
 * 检查用户的登录信息
 */
const BASE_URL = uni.BASE_URL
export const checkUserinfo = () => {
	const userinfo_update = uni.getStorageSync('userinfo')
	console.log(userinfo_update)
	if (!userinfo_update || !userinfo_update.uid || userinfo_update=='') {
		setTimeout(function() {
			uni.navigateTo({
				url: '/pages/public/login',
			});
		}, 1500)
	} else {
		// 获取用户信息是否最新用的
		uni.request({
			url: BASE_URL + 'index/user/update_userdata',
			data: {
				uid: userinfo_update.uid,
			},
			method: 'POST',
			success: (res) => {
				const userinfo_check = uni.getStorageSync('userinfo');
				if (res.data.code == 200) {
					const userdata = res.data.data
					userinfo_check.userdata = userdata
					uni.setStorageSync('userinfo', userinfo_check)
				} else {
					uni.showToast({
						title: res.data.msg,
						duration: 2000,
						icon: 'none'
					});
					uni.removeStorageSync('userinfo');
					setTimeout(function() {
						uni.navigateTo({
							url: '/pages/public/login',
						});
					}, 1500)
				}
			},
			fail: (err) => {

			}
		});
	}
}
